//
//  stdArray.cpp
//  learnC++
//
//  Created by apple on 2018/5/30.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "stdArray.hpp"

using namespace std;

void printLength(const std::array<int, 5> &myArray)
{
    cout << "length: " << myArray.size() << endl;
}

//C ++内置固定数组
void test_std_array(){
    
    //缺点：必须传数组长度来处理
    std::array<int, 5> arr;
    arr = {1,2,3};
    //reference
    std::array<int, 5> &ref = arr;
    
    std::array<int, 5> arr2{9,2,8,4,1};
    
    //数组里面包含数组
    std::array<int , 5> arrs[]{arr,arr2};
    
    
    cout << arr2[1] << endl;
    
    //提供边界检测
    arr.at(1) = 3;
//    arr.at(9) = 2;//throw_error = out of range
    
    
    cout << arr.size() << endl;
    
    //    std::array指针不会衰减
    //总是通过引用或const引用传递std :: array
    printLength(ref);
    
    for(auto &element : arr2){
        cout << element << endl;
    }
    
    std::sort(arr2.begin(), arr2.end());
    
    for(auto &element : arr2){
        cout << element << endl;
    }
}

